package com.iot.blackip.controller;

import com.dc3.common.bean.R;
import com.iot.blackip.dto.Dc3BlackIpDto;
import com.iot.blackip.service.BlackIpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 咕唧
 * @Date 2022/7/20 19:31
 * @Version 1.0
 */
@RestController
@RequestMapping("/blackip")
public class BlackIpController {
    private BlackIpService blackIpService;

    @Autowired
    public void setBlackIpService(BlackIpService blackIpService) {
        this.blackIpService = blackIpService;
    }

    @PostMapping("/add")
    public R addBlackIp(@RequestBody Dc3BlackIpDto dc3BlackIpDto) {
        blackIpService.addBlackIp(dc3BlackIpDto);
        return R.ok();
    }

    @PostMapping("/list/simple")
    public R findAllIp2Dto() {
        return R.ok(blackIpService.findAllIp2Dto());
    }

    @PostMapping("/delete")
    public R deleteIp(String id) {
        return R.ok(blackIpService.deleteBlackIp(id));
    }

    @PostMapping("/refresh")
    public R refreshCache() {
        blackIpService.refresh();
        return R.ok();
    }

}
